package jeecg.system.service.impl;

import java.util.List;

import jeecg.system.pojo.base.TSUser;
import jeecg.system.service.UserService;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service("userService")
@Transactional
public class UserServiceImpl extends CommonServiceImpl implements UserService {

	public TSUser checkUserExits(TSUser user){
		return this.commonDao.getUserByUserIdAndUserNameExits(user);
	}
	public String getUserRole(TSUser user){
		return this.commonDao.getUserRole(user);
	}
	@Override
	public void pwdInit(TSUser user,String newPwd) {
			this.commonDao.pwdInit(user,newPwd);
	}
	@Override
	public void updateUser(TSUser user) {
		 TSUser tsUser = queryUserById(user.getId());
		 if(tsUser!=null){
			 tsUser.setUserName(user.getUserName());
			 tsUser.setIsLogin(user.getIsLogin());
			 tsUser.setRealName(user.getRealName());
			 tsUser.setIdentity(user.getIdentity());
			 tsUser.setMobilePhone(user.getMobilePhone());
			 tsUser.setOfficePhone(user.getOfficePhone());
			 tsUser.setEmail(user.getEmail());
		 }
		 this.commonDao.saveOrUpdate(tsUser);
	}
	@Override
	public TSUser queryUserById(String userId) {
		return this.commonDao.get(TSUser.class, userId);
	}
	
	public TSUser queryUserByName(String userName){
		String hql = " from TSUser where username = '"+userName+"'";
		List<TSUser> ulist = findByQueryString(hql);
		if(ulist != null && ulist.size() > 0) return ulist.get(0);
		return null;
	}
	
	@Override
	public void updatePassword(TSUser user) {
		 this.commonDao.saveOrUpdate(user);
	}
}
 